/* GSManufactureExcelRomoveAction.java
 *
 * Project/Product: APEP-JZCG
 *
 * Modify Information:
 * =============================================================================
 *   Author	Date       Description
 *   ----------	---------- ---------------------------------------------------
 *   peng.ning	2008-10-27	First release
 *
 * Licensed Materials - Property of APEP
 * =============================================================================
 *    (C) COPYRIGHT Shanghai Auto Mart E-Procurement Co., Ltd. 2007 - 2008
 *    All Rights Reserved.
 *
 *    This software is the confidential and proprietary information of
 *    Shanghai Auto Mart E-Procurement Co., Ltd. ("Confidential Information").
 *    You shall not disclose such Confidential Information and shall use it only
 *    in accordance with the terms of the license agreement you entered into 
 *    with Shanghai Auto Mart E-Procurement Co., Ltd.
 *
 * Noties:
 * =============================================================================
 * 
 */

package com.hitrust.gs.action;

import java.util.ArrayList;
import com.hitrust.gs.form.GSProductUpdateIsbuyForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.util.page.ResultProcess;
import com.hitrust.gs.vo.GSProductUpdateIsbuyView;

public class GSProductUpdateIsbuyExcelRomoveAction extends GSBaseAction {

    /* (non-Javadoc)
     * @see com.apep.jzcg.service.GSBaseAction#execute(com.apep.jzcg.service.GSBaseForm)
     */
    public String execute(GSBaseForm aForm) throws Exception {
        // TODO Auto-generated method stub
    	GSProductUpdateIsbuyForm mform=(GSProductUpdateIsbuyForm) aForm;
        String[] index=mform.getSel_manufacture();
       	String type=(String)aForm.getRequest().getParameter("type");
        try {
 
            ResultProcess rst=null;
        		if("0".equals(type)){
        		  rst= (ResultProcess) aForm.getSession().getAttribute("productUpdateIsbuyOffExcel");
        		}else{
        		  rst= (ResultProcess) aForm.getSession().getAttribute("productUpdateIsbuyOnExcel");
        		}
           
            ArrayList array=rst.getAllRecoreds();
            for (int i = 0; i < index.length; i++) {
                for (int j = 0; j < array.size(); j++) {
                	GSProductUpdateIsbuyView mv=(GSProductUpdateIsbuyView) array.get(j);
                    if (index[i].equals(mv.getGs_recorder_id())) {
                        array.remove(mv);
                    }
                }
            }
            if (array!=null&&array.size()==0) {
            	if("0".equals(type)){
                  aForm.getSession().removeAttribute("productUpdateIsbuyOffExcel");
                  aForm.getRequest().setAttribute("message", "移除产品关闭信息成功，无可移除产品关闭信息，返回继续添加");
          		}else{
                  aForm.getSession().removeAttribute("productUpdateIsbuyOnExcel");
                  aForm.getRequest().setAttribute("message", "移除产品启用信息成功，无可移除产品启用信息，返回继续添加");
          		}

                aForm.getRequest().setAttribute("action", "A190008.do?type="+type);
            }else if(array!=null&&array.size()>0){
             	if("0".equals(type)){
             		aForm.getRequest().setAttribute("message", "移除产品关闭信息成功");
                    rst.setResult(array);
                    aForm.getSession().setAttribute("productUpdateIsbuyOffExcel", rst);
            		}else{
            		aForm.getRequest().setAttribute("message", "移除产品启用信息成功");
                    rst.setResult(array);
                    aForm.getSession().setAttribute("productUpdateIsbuyOnExcel", rst);	
            		}
                if (aForm.getRequest().getParameter("choice").equals("")) {
                    aForm.getRequest().setAttribute("action", "A190010.do?type="+type);
                }
            }
        } catch (Exception e) {
            aForm.getRequest().setAttribute("action", "A190010.do?type="+type);
            aForm.getRequest().setAttribute("target", "_self");
            throw new GSException(e.getMessage());
        }
        
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
